package com.cy.pj.students.studentscontroller;

import com.cy.pj.students.pojo.Students;
import com.cy.pj.students.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/students")
public class StudentsController {

    @Autowired
    private StudentsService studentsService;

    //查询业务
    @RequestMapping("/doFindAll")
    public String doFindAll(Model model){
        List<Students> list = studentsService.findAll();
        model.addAttribute("students", list);
        return "students";
    }

    //新增业务
    @RequestMapping("/doInsert")
    public String doInsert(){
        return "studentsAdd";
    }
    @RequestMapping("/doSaveStudents")
    public String doSaveStudents(Students students){
        studentsService.insert(students);
        return "forward:doFindAll";
    }

    //修改业务
    @RequestMapping("/doFindById")
    public String doFindById(Integer id, Model model){
        Students students =  studentsService.findById(id);
        model.addAttribute("students", students);
        return "studentsUpdate";
    }
    @RequestMapping("/doUpdateStudents")
    public String doUpdateStudents(Students students){
        studentsService.updateStudents(students);
        return "forward:doFindAll";
    }

    //删除业务
    @RequestMapping("/doDeleteById")
    public String doDeleteById(Integer id){
        studentsService.deleteStudents(id);
        return "forward:doFindAll";
    }
}


















